package defpackage; import cn.wps.moffice.OfficeApp; import cn.wps.moffice.main.common.ServerParamsUtil; import com.google.gson.Gson; import defpackage.ghu; import java.io.IOException; import java.util.ArrayList; import java.util.List; import org.json.JSONException; import org.json.JSONObject; /* renamed from: gkn reason: default package */ public final class gkn { public static List<ghu> T(String str, int i) { gkp gkp; String str2; String str3; ArrayList<String> arrayList; int i2 = 0; try { ArrayList arrayList2 = new ArrayList(); try { gkp = (gkp) new Gson().fromJson(n(str, i, 8), gkp.class); } catch (Exception e) { e.printStackTrace(); gkp = null; } boolean z = true; if (gkp == null || lwv.isEmpty(gkp.result) || !"ok".equals(gkp.result.toLowerCase())) { z = false; } ghu ghu = new ghu(); ghu.gEV = 10; ghu.extras = new ArrayList(); gkq gkq = new gkq(); gkq.bUG = "“" + str + "”"; gkq.tag = "keyword"; ghu.extras.add(new ghu.a("object", gkq)); ghu.extras.add(new ghu.a("keyword", str)); ghu.extras.add(new ghu.a("template_type", Integer.valueOf(i))); arrayList2.add(ghu); if (z && (arrayList = gkp.hgD) != null && arrayList.size() > 0) { while (i2 < arrayList.size() && i2 < 8) { ghu ghu2 = new ghu(); ghu2.gEV = 11; ghu2.extras = new ArrayList(); gkq gkq2 = new gkq(); gkq2.bUG = arrayList.get(i2); gkq2.tag = gkp.tag; ghu2.extras.add(new ghu.a("object", gkq2)); ghu2.extras.add(new ghu.a("keyword", str)); ghu2.extras.add(new ghu.a("template_type", Integer.valueOf(i))); arrayList2.add(ghu2); i2++; } } if (ServerParamsUtil.tH("template_think_word_ad_item")) { ServerParamsUtil.Params tG = fvd.tG("template_think_word_ad_item"); if (tG == null || tG.extras == null) { str2 = null; str3 = null; } else { str2 = null; String str4 = null; for (ServerParamsUtil.Extras extras : tG.extras) { if ("title".equalsIgnoreCase(extras.key)) { str4 = extras.value; } else { str2 = "jump_url".equalsIgnoreCase(extras.key) ? extras.value : str2; } } str3 = str4; } if (!lwv.isEmpty(str3) && !lwv.isEmpty(str2)) { gko gko = new gko(); gko.url = str2; gko.title = str3; ghu ghu3 = new ghu(); ghu3.gEV = 12; ghu3.extras = new ArrayList(); ghu3.extras.add(new ghu.a("object", gko)); ghu3.extras.add(new ghu.a("template_type", Integer.valueOf(i))); arrayList2.add(ghu3); } } return arrayList2; } catch (Exception e2) { return null; } } private static String n(String str, int i, int i2) { try { JSONObject jSONObject = new JSONObject(); jSONObject.put("key", str); jSONObject.put("app", String.valueOf(i)); jSONObject.put("num", 8); jSONObject.put("uuid", OfficeApp.arx().arG()); return lwd.z(lwd.a("https://thinker.ksord.com/nova/android", jSONObject.toString(), null, 3000)); } catch (IOException e) { e.printStackTrace(); return ""; } catch (JSONException e2) { e2.printStackTrace(); return ""; } } }